package o;

import android.text.TextUtils;
import android.util.Patterns;
import com.huawei.hms.framework.common.SystemPropUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;

public class cnr {

    static class a extends Thread {
        private InetAddress[] ˏ;
        private String ॱ;

        a(String str) {
            this.ॱ = str;
        }

        synchronized InetAddress[] ˋ() {
            return this.ˏ;
        }

        private synchronized void ॱ(InetAddress[] inetAddressArr) {
            this.ˏ = inetAddressArr;
        }

        public void run() {
            try {
                ॱ(InetAddress.getAllByName(this.ॱ));
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static boolean ˎ(java.lang.String r7, int r8) {
        /*
        r0 = 0;
        r1 = r7.isEmpty();
        if (r1 == 0) goto L_0x0008;
    L_0x0007:
        return r0;
    L_0x0008:
        r2 = new java.net.Socket;
        r2.<init>();
        r1 = new java.net.InetSocketAddress;	 Catch:{ IOException -> 0x0029 }
        r1.<init>(r7, r8);	 Catch:{ IOException -> 0x0029 }
        r3 = 4000; // 0xfa0 float:5.605E-42 double:1.9763E-320;
        r2.connect(r1, r3);	 Catch:{ IOException -> 0x0029 }
        r2.close();	 Catch:{ IOException -> 0x001c }
    L_0x001a:
        r0 = 1;
        goto L_0x0007;
    L_0x001c:
        r0 = move-exception;
        r1 = o.cmp.ˊ;
        r2 = "Utils";
        r0 = r0.toString();
        r1.ˊ(r2, r0);
        goto L_0x001a;
    L_0x0029:
        r1 = move-exception;
        r3 = o.cmp.ˊ;	 Catch:{ all -> 0x006d }
        r4 = "Utils";
        r5 = new java.lang.StringBuilder;	 Catch:{ all -> 0x006d }
        r5.<init>();	 Catch:{ all -> 0x006d }
        r6 = "ip connect failed: ";
        r5 = r5.append(r6);	 Catch:{ all -> 0x006d }
        r5 = r5.append(r7);	 Catch:{ all -> 0x006d }
        r6 = " port: ";
        r5 = r5.append(r6);	 Catch:{ all -> 0x006d }
        r5 = r5.append(r8);	 Catch:{ all -> 0x006d }
        r6 = ", exception:";
        r5 = r5.append(r6);	 Catch:{ all -> 0x006d }
        r1 = r1.toString();	 Catch:{ all -> 0x006d }
        r1 = r5.append(r1);	 Catch:{ all -> 0x006d }
        r1 = r1.toString();	 Catch:{ all -> 0x006d }
        r3.ˋ(r4, r1);	 Catch:{ all -> 0x006d }
        r2.close();	 Catch:{ IOException -> 0x0060 }
        goto L_0x0007;
    L_0x0060:
        r1 = move-exception;
        r2 = o.cmp.ˊ;
        r3 = "Utils";
        r1 = r1.toString();
        r2.ˊ(r3, r1);
        goto L_0x0007;
    L_0x006d:
        r0 = move-exception;
        r2.close();	 Catch:{ IOException -> 0x0072 }
    L_0x0071:
        throw r0;
    L_0x0072:
        r1 = move-exception;
        r2 = o.cmp.ˊ;
        r3 = "Utils";
        r1 = r1.toString();
        r2.ˊ(r3, r1);
        goto L_0x0071;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.cnr.ˎ(java.lang.String, int):boolean");
    }

    public static String[] ˋ(String str) {
        int i = 0;
        if (TextUtils.isEmpty(str)) {
            return new String[0];
        }
        try {
            a aVar = new a(new URL(str).getHost());
            aVar.start();
            try {
                aVar.join(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            InetAddress[] ˋ = aVar.ˋ();
            if (ˋ == null) {
                return new String[0];
            }
            String[] strArr = new String[ˋ.length];
            while (i < ˋ.length) {
                strArr[i] = ˋ[i].getHostAddress();
                i++;
            }
            return strArr;
        } catch (MalformedURLException e2) {
            cmp.ˊ.ˋ("Utils", "domain parse failed:" + str + ", exception:" + e2.toString());
            return new String[0];
        }
    }

    public static String ˊ(String str) {
        if (!str.startsWith("http")) {
            str = "https://" + str;
        }
        String[] split = str.split(":");
        int i = 0;
        while (i < split.length) {
            if (Patterns.IP_ADDRESS.matcher(split[i]).matches()) {
                break;
            }
            i++;
        }
        i = 0;
        if (i == 0) {
            return str;
        }
        String replace = str.replace(":" + split[i], "");
        cmp.ˊ.ˎ("Utils", "non-standard domain detected, correcting... before: " + str + ", after: " + replace);
        return replace;
    }

    public static void ˎ(String str, String str2) {
        OutputStream fileOutputStream;
        IOException e;
        Throwable th;
        cmp.ˊ.ˋ("Utils", "file path:" + str2);
        try {
            fileOutputStream = new FileOutputStream(new File(str2));
            try {
                fileOutputStream.write(str.getBytes(StandardCharsets.UTF_8));
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e2) {
                        cmp.ˊ.ˊ("Utils", "close file failed, " + e2.toString());
                    }
                }
            } catch (IOException e3) {
                e2 = e3;
                try {
                    cmp.ˊ.ˊ("Utils", "open file failed, " + e2.toString());
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e22) {
                            cmp.ˊ.ˊ("Utils", "close file failed, " + e22.toString());
                        }
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e4) {
                            cmp.ˊ.ˊ("Utils", "close file failed, " + e4.toString());
                        }
                    }
                    throw th;
                }
            }
        } catch (IOException e5) {
            e22 = e5;
            fileOutputStream = null;
            cmp.ˊ.ˊ("Utils", "open file failed, " + e22.toString());
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
        } catch (Throwable th3) {
            th = th3;
            fileOutputStream = null;
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            throw th;
        }
    }

    public static String ˏ(String str, String str2) {
        return SystemPropUtils.getProperty("get", str, "android.os.SystemProperties", str2);
    }
}
